# -*- coding:utf-8 -*-
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
class Solution:
    # 返回构造的TreeNode根节点
    def reConstructBinaryTree(self, pre, tin):
        
        # 递归 root是pre[0]，再找出来左子树和右子树前序和中序
        if pre == []:
            return None
        else:
            node = TreeNode(pre[0])
            index = tin.index(pre[0])
            if index == -1:
                return None
            
            # pre[1:index+1]：左子树的前序， tin[:index]：左子树的中序
            node.left = self.reConstructBinaryTree(pre[1:index+1], tin[:index])
            node.right = self.reConstructBinaryTree(pre[index+1:], tin[index+1:])

            return node
        # write code here